//
//  UIViewExtension.swift
//  DateNote
//
//  Created by 杨立鹏 on 2017/12/8.
//  Copyright © 2017年 杨立鹏. All rights reserved.
//

import Foundation
import UIKit
extension UIView{
    
    func randomSubViewsColor() {
        
        if self.subviews.count > 0 {
            for view:UIView in self.subviews {
                view.backgroundColor = .randomColor
                view.randomSubViewsColor()
            }
        }
    }
}

extension CGRect {
    var center: CGPoint{
        return CGPoint(x: (maxX - minX) * 0.5, y: (maxY - minY) * 0.5)
    }
}

extension UIView {
    enum UIViewSingleLineType {
        case top
        case bottom
        case left
        case right
    }
    
    func setBorder(type: UIViewSingleLineType, width: CGFloat, color: UIColor) {
        let layer = CALayer()
        
        switch type {
        case .top:
            layer.frame = CGRect(x: 0, y: 0, width: self.frame.size.width, height: width)
        case .bottom:
            layer.frame = CGRect(x: 0, y: self.frame.size.height - width, width: self.frame.size.width, height: width)
        case .left:
            layer.frame = CGRect(x: 0, y: 0, width: width, height: self.frame.size.height)
        case .right:
            layer.frame = CGRect(x: self.frame.size.width - width, y: 0, width: width, height: self.frame.size.height)
        }
        layer.backgroundColor = color.cgColor
        
        self.layer.addSublayer(layer)
    }
 
}


